﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Domain.Entity;

namespace Domain.Provider.Dummy
{
    public class StoreProvider : IDataProvider<Store>
    {
        private static List<Store> _entities { get; set; }
        private static Random rand = new Random();

        static StoreProvider()
        {
            _entities = new List<Store>();

            for (int i = 0; i < 100; i++)
            {
                var hours = new List<WeeklyStoreHours>();

                for (int j = 0; j < 10; j++)//rand.Next(10)
                    hours.Add(generateWeeklyStoreHours(i, j));

                _entities.Add(new Store { ID = i, Name = ""+i, AllHours = hours });
            }
        }
        private static StoreHours generateStoreHours()
        {
            var startTime = DateTime.Now.AddHours(rand.Next(12));
            var endTime = DateTime.Now.AddHours(rand.Next(12) + 12);

            startTime = startTime.AddMinutes(-startTime.Minute + rand.Next(2) * 30);
            endTime = endTime.AddMinutes(-endTime.Minute + rand.Next(2) * 30);

            return new StoreHours { StartTime = startTime, EndTime = endTime, Closed = rand.Next(2) == 0 };
        }
        private static WeeklyStoreHours generateWeeklyStoreHours(int StoreId, int weeklyId)
        {
            
            var weeklyStoreHours = new WeeklyStoreHours
            { 
                EffectiveDate = DateTime.Now,
                MondayDate = DateTime.Now.AddDays(1),
                TuesdayDate = DateTime.Now.AddDays(2),
                WednesdayDate = DateTime.Now.AddDays(3),
                ThursdayDate = DateTime.Now.AddDays(4),
                FridayDate = DateTime.Now.AddDays(5),
                SaturdayDate = DateTime.Now.AddDays(6),
                SundayDate = DateTime.Now.AddDays(7)
            };
            weeklyStoreHours.storeId = StoreId;
            weeklyStoreHours.weeklyID = weeklyId;
            weeklyStoreHours.EffectiveDate = weeklyStoreHours.EffectiveDate.AddMonths(rand.Next(12) * (rand.Next(2) == 0 ? -1 : 1));
            weeklyStoreHours.EffectiveDate = weeklyStoreHours.EffectiveDate.AddDays(rand.Next(31) * (rand.Next(2) == 0 ? -1 : 1));

            weeklyStoreHours.MondayHours = generateStoreHours();
            weeklyStoreHours.TuesdayHours = generateStoreHours();
            weeklyStoreHours.WednesdayHours = generateStoreHours();
            weeklyStoreHours.ThursdayHours = generateStoreHours();
            weeklyStoreHours.FridayHours = generateStoreHours();
            weeklyStoreHours.SaturdayHours = generateStoreHours();
            weeklyStoreHours.SundayHours = generateStoreHours();

            return weeklyStoreHours;
        }
        public IEnumerable<Store> Entities
        {
            get { return _entities; }
        }

        public void SaveEntity(Store entity)
        {
           
        }

        public void DeleteEntity(Store entity)
        {
            throw new NotSupportedException();
        }
    }
}
